public class Demo {
    public static void main(String[] args) {
//        Alg<String> stringAlg = new Alg<>();
        Alg<Integer> integerAlg = new Alg<>();
        Integer[] arrays = {1,2,3,4,5,6,7,8,9,10};
        System.out.println(integerAlg.findMax(arrays));
    }
}
class Alg<T extends Comparable<T>>{//T一定是实现Compareable接口的
    public T findMax(T[] array){
    T max = array[0];
        for (int i = 0; i < array.length; i++) {
            if(array[i].compareTo(max) > 0){
                max = array[i];
            }
        }
        return max;
    }

}
class Alg2{
    //泛型方法
    public static<T extends Comparable<T>> T findMax(T[] array){
        T max = array[0];
        for (int i = 0; i < array.length; i++) {
            if(array[i].compareTo(max) > 0){
                max = array[i];
            }
        }
        return max;
    }

    public static void main(String[] args) {
        Integer[] arrays = {1,2,3,4,5,6,7,8,9,10};
        System.out.println(findMax(arrays));
    }

}
